From 7545be423c264f501818d8a26b5c7f37bdea4c56 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 1 Jul 2005 21:24:09 +0000 Subject: [PATCH] Improve the IDE HD geometry auto detection algorithm. Signed-off-by: Nitin A Kamble Signed-off-by: Asit K Mallick Signed-off-by: Arun Sharma --- tools/ioemu/hw/ide.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/ioemu/hw/ide.c b/tools/ioemu/hw/ide.c index bc7ebd3205..5e5610e136 100644 --- a/tools/ioemu/hw/ide.c +++ b/tools/ioemu/hw/ide.c @@ -1850,7 +1850,11 @@ static void ide_guess_geometry(IDEState *s) a cylinder boundary */ s->heads = p->end_head + 1; s->sectors = p->end_sector & 63; + if (s->sectors == 0) + continue; s->cylinders = s->nb_sectors / (s->heads * s->sectors); + if (s->cylinders < 1 || s->cylinders > 16383) + continue; #if 0 printf("guessed partition: CHS=%d %d %d\n", s->cylinders, s->heads, s->sectors); @@ -1884,8 +1888,12 @@ static void ide_init2(IDEState *ide_state, int irq, s->sectors = secs; } else { ide_guess_geometry(s); - if (s->cylinders == 0) { - /* if no geometry, use a LBA compatible one */ + + /* if heads > 16, it means that a BIOS LBA + translation was active, so the default + hardware geometry is OK */ + if ((s->heads > 16) || (s->cylinders == 0)) { + /* if no geometry, use a standard physical disk geometry */ cylinders = nb_sectors / (16 * 63); if (cylinders > 16383) cylinders = 16383; -- 2.30.2